package test_0523;

public class test01_binarySort {
    public static void main(String[] args) {
        int[] arr = new int[]{1,5,3,6,4,7,8,10,9,2};
        int len = arr.length - 1;
        for (int i = 0; i <= len; i++) {
            System.out.print(arr[i] +" ");
        }
        System.out.println();
        binary_Sort.binarySort(arr,0,len);
        for (int i = 0; i <= len ; i++) {
            System.out.print(arr[i] +" ");
        }
    }
}
class binary_Sort{
    public static void binarySort(int[] arr,int left,int right){
        int tmp,i ,j;
        if(left >= right){
            return;
        }
        tmp = arr[left];
        j = right;
        i = left;
        while(i < j){
           while(arr[j] >= tmp && i < j) {
               j--;
           }
           while(arr[i] <= tmp && i < j) {
                i++;
           }
           int tmp2 = arr[i];
           arr[i] = arr[j];
           arr[j] = tmp2;

        }
        arr[left] = arr[i];
        arr[i] = tmp;
        binarySort(arr,0,i - 1);
        binarySort(arr,i + 1,right);
    }

}